import pandas as pd

df = pd.read_csv('data/learn_pandas.csv', usecols=['School', 'Grade', 'Name', 'Gender', 'Weight', 'Transfer'])
print('取出姓名一列\n', df['Name'].head())

print('取出多列\n', df[['Gender', 'Name']].head())

s = pd.Series([1, 2, 3, 4, 5, 6], index=['a', 'b', 'a', 'a', 'a', 'c'])
print('Series单个值对应\n', s['a'])
print('Series多个值对应\n', s[['c', 'b']])

df_demo = df.set_index('Name')
print('数据前五行\n', df_demo.head())

print('直接取出相应的列(数据重复)\n', df_demo.loc['Qiang Sun'])
print('直接取出相应的列(数据不重复)\n', df_demo.loc['Quan Zhao'])

print('同时选择行和列\n', df_demo.loc['Qiang Sun', 'School'])

print('取出列表中所有元素值对应的行或列\n', df_demo.loc[['Qiang Sun', 'Quan Zhao'], ['School', 'Gender']])

print('第二行第二列\n', df_demo.iloc[1, 1])
print('前两行前两列\n', df_demo.iloc[[0, 1], [0, 1]])

print('第二到四行，三到四列\n', df_demo.iloc[1: 4, 2:4])
